package com.example.test_aidl_carservice

import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.util.Log

class CarService : Service() {
    override fun onCreate() {
        super.onCreate()
    }

    override fun onDestroy() {
        super.onDestroy()
    }

    override fun onUnbind(intent: Intent?): Boolean {
        return super.onUnbind(intent)
    }

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        return super.onStartCommand(intent, flags, startId)
    }
    override fun onBind(intent: Intent): IBinder {
        return  object :IMyAidlInterface.Stub(){
            override fun getSpeed(): Int {
                //can总线返回车速
                Thread.sleep(6000)
                return 100
            }

            override fun openBackDoor() {
                //通知can总线打开后备箱
                Log.d("CarService", "打开后备箱: ")
            }

            override fun getSpeed2(callback: IMyCallBack?) {
                Thread.sleep(5000)
                callback?.onSuccess(200) //异步回调
            }

            override fun add(a: Int, b: Int, result: ResultHolder?) {
                //修改result
                result?.value = a+b
            }

        }
    }
}